package concurrent.push;

import org.apache.commons.lang3.StringUtils;

import java.util.*;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Author: Jason Wu
 * Date  : 2013-12-20
 */
public class QueueManager {
    private Map<String, PushingTask> taskQueue;

    private static Set<String> cancelledTasks = Collections.synchronizedSet(new HashSet<String>());

    public void add(PushingTask task) {
        taskQueue.put(task.getKey(), task);
    }

    public void remove(PushingTask task) {
        taskQueue.remove(task.getKey());
    }

    public boolean isCancelled(String taskKey) {
        return cancelledTasks.contains(taskKey);
    }

    public void cancel(String key) {
        PushingTask task = taskQueue.get(key);
        if (task != null) {
            task.cancel();
        }
    }

    public void matchCancel(String keyPattern) {
        for (String taskKey : taskQueue.keySet()) {
            //StringUtils.startsWithIgnoreCase(taskKey,key);
        }
    }

    public static void main(String[] args) {
        String key = "Hotel:RatePlanA:RoomTypeB";
        String regex = "^Hotel*";
        System.out.println(key.matches(regex));
    }
}
